package fr.univ.surveyonline.question.xmlbuilder.balises;

import java.util.HashMap;
import java.util.Map;

import org.xml.sax.Attributes;

import fr.univ.surveyonline.question.xmlbuilder.SurveyXMLException;


public class AllBalises {

	public static Map<String,String> equals(Attributes at, String[] attributes) throws SurveyXMLException {
		if (at.getLength() != attributes.length) {
			throw new SurveyXMLException("Pas le bon nombre d'attribut");
		}
		Map<String,String> at2 = new HashMap<String,String>();
		for (int i =0; i < at.getLength(); i++) {
			String parameter = at.getLocalName(i);
			String value = at.getValue(i);
			at2.put(parameter.toLowerCase(),value);
		}
		
		
		Map<String,String> map = new HashMap<String,String>();
		
		for (String s : attributes) {
			String value = at2.get(s);
			if (value == null) {
				throw new SurveyXMLException(s + " : Attribut manquant !");
			}			
			map.put(s, value);
		}
		/*
		for (String s : attributes) {
			int i = at.getIndex(s);
			if (i == -1) {
				throw new SurveyXMLException(s + " : Attribut manquant !");
			}
			map.put(s, at.getValue(i));
		}
		*/
		return map;
	}
}
